/*-------------------------------------------------------------------------------\ | SOURCE: filescan.sas | | | | VERSION: RDS v3.0 | | Part of the SPIKEware Rapid Decision Support SAS Macro Package | | for SAS v8.x and above | | | | PURPOSE: This macro scans an input file for occurences of all variable names | | in a given SAS dataset. It is designed to scan a SAS program to | | determine if there are any variables in a SAS dataset that are not | | used by that program. If so, the macro prints a report. If not, | | a note is put in the log. | | | | SYNTAX: %filescan (data = _SAS_dataset_name_, | | file = _SAS_program_file_to_scan_) | | | | DATE DESCRIPTION BY | | ======== =================================================== ============= | | 09/15/02 migrated to version 3.0 for use with SAS v8.x Paul McDonald | | | | Notes: | | | +--------------------------------------------------------------------------------+ | LICENSE: This library is free software--you can redistribute it and/or | | modify it under the terms of the GNU Lesser General Public | | License as published by the Free Software Foundation--either | | version 2.1 of the License, or (at your option) any later version. | | | | This library is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY--without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | Lesser General Public License for more details. | | | | You should have received a copy of the GNU Lesser General Public | | License along with this library--if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | | | | OSI: This software is OSI Certified Open Source Software. | | OSI Certified is a certification mark of the Open Source Initiative. | | | | CREDITS: This software program is the intellectual property of SPIKEware, Inc. | | | | SAS, the SAS Software System, and its components are property | | of the SAS Institute, Inc. in Cary, NC http://www.sas.com/ | | | | SUPPORT: Visit our website to download the most current version and our | | training and documentation for this and other SPIKEware utilities. | | | | WOOF! (c) 1997, 2002 by SPIKEware, Inc. | | 115 1/2 West Main Street | | West Dundee, IL 60118 | | http://www.SPIKEware.com/ | \-------------------------------------------------------------------------------*/ ; %macro filescan (indata=, file=) /des='Scans a file for variable names' ; %let notes = %sysfunc(getoption(notes,keyword)) ; options nonotes ; %let starttime = %sysfunc(datetime()) ; proc contents data=&indata noprint out=macro.contents (keep = name) ; run ; proc transpose data=macro.contents out=macro.tranny (keep = col1-col%obscnt(macro.contents)) ; var name ; run ; data macro.view1 (keep = line n name) /view=macro.view1 ; if _n_ = 1 then set macro.tranny ; infile &file pad ; label n = 'Line number in source code' name = 'Variable name' line = 'Line of source code' ; input @1 line $200. ; n = _n_ ; %do i = 1 %to %obscnt(macro.contents) ; if indexw(line, col&i) ne 0 then do ; name = col&i ; output ; end ; %end ; run ; proc sort data=macro.view1 out=macro.sorted1 ; by name ; run ; data macro.missed (keep = name data file) ; merge macro.contents (in = in1) macro.sorted1 (in = in2) ; by name ; if in1 and not in2 ; label data = 'Input Dataset Name' file = 'SAS Source Code File Scanned' ; retain data "&indata" file "&file" ; run ; %if %obscnt(macro.missed) = 0 %then %do ; options ¬es ; %put NOTE: No report will be generated because all variables in %data(&indata) were found in file %trim(%left(&file)). ; options nonotes ; %end ; %else %do ; proc print data=macro.missed label ; id name ; var data file ; run ; options ¬es ; %put NOTE: Macro FILESCAN printed a report of variables in %data(&indata) not found in file %trim(%left(&file)). ; options nonotes ; %end ; proc datasets library=macro nolist ; delete missed contents sorted1 view1 tranny ; quit ; options nonotes ; %timenote (macro=filescan, starttime=&starttime) %put ; options ¬es ; %mend filescan ;